package com.vic.mvc.prepare.design.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class  TestHanlder{
	
}
/**
 * 汽车行驶的日志代理
 */
class LogHanlder implements InvocationHandler {
	Object target;
	
	public LogHanlder(Object target){
		this.target = target;
	}
	@Override
	public Object invoke(Object obj, Method m, Object[] arg2) throws Throwable {
		System.out.println("日志：开始行驶");
		m.invoke(target);
		System.out.println("日志：结束行驶");
		return null;
	}

}
/**
 * 汽车行驶的时间代理
 */
class TimeHandler implements InvocationHandler {
	
	Object target;
	public TimeHandler(Object target){
		this.target = target;
	}
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		long t1 = System.currentTimeMillis();
		method.invoke(target);
		long t2 = System.currentTimeMillis();
		System.out.println("本次行驶时间：" + (t2 - t1) +" 毫秒");
		return null;
	}
	
	
}
